# 贪心算法 跳跃游戏2


class Solution:
    def jump(self, nums):
        ans = 0
        start = 0
        end = 1

        while end < len(nums):
            maxPos = 0
            # 统计最远可以跳跃的距离
            for i in range(start, end):

                maxPos = max(maxPos, i + nums[i])
            # 更新下一步起跳的范围
            start = end
            end = maxPos + 1
            ans = ans + 1
        

        return ans
    

if __name__ == "__main__":
    nums = [2, 3, 1, 1, 4]
    sol = Solution()
    res = sol.jump(nums)
    print(res)


